package com.suse.springmvcdemo2.controller;


import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/requset")
public class RequestController {
    @RequestMapping("/setSession")
    public String setSession(HttpServletRequest request) {
        HttpSession session = request.getSession(true);
        session.setAttribute("name","zhangsan");
        session.setAttribute("student","12312");
        return  "设置成功";
    }

    @RequestMapping("/getSession")
    public String getSession(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if(session != null) {
            System.out.println(session.getAttribute("name"));
            System.out.println(session.getAttribute("student"));
        }
        return "获取Session成功";
    }

}
